const qiniu = require('qiniu');
const QINIU_AK = '8T-uJjhTJJMHrzPm6h2em-_7LZpOXimHUFCGpVEf';
const QINIU_SK = 'j7od6uuR2zXFmdTdgwRjCTzPw1G2iYS13fzHhllD';
const QINIU_RTN_APPID = 'dumtvmlhj';
const QINIU_CREDENTIALS = new qiniu.Credentials(QINIU_AK, QINIU_SK);


const server = {
    /**
     * 获取RoomToken
     * */
    GetRoomToken: async (data) => {
        let userId = data.userId;
        let roomName = data.roomName;
        let roomToken = qiniu.room.getRoomToken({
            appId: QINIU_RTN_APPID,
            roomName: roomName,
            userId: userId,
            expireAt: Date.now() + (1000 * 60 * 60 * 3), // token 的过期时间默认为当前时间之后 3 小时
            permission: 'admin', // 默认所有的用户权限都是 admin，都可以踢人
        }, QINIU_CREDENTIALS);
        return roomToken
    }
};

module.exports = server;